package com.tool4j.controller;

import com.tool4j.entity.TermInfo;
import com.tool4j.service.TermInfoService;
import com.tool4j.util.UserPermission;
import com.tool4j.util.http.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ServerWebExchange;

import java.util.List;

@RestController
@RequestMapping("/api/term")
public class TermInfoController {

    @Autowired
    private TermInfoService termInfoService;

    @GetMapping("/getAll")
    public Result<List<TermInfo>> getAll(ServerWebExchange exchange) {
        Long userId = UserPermission.get(exchange).getUserId();
        List<TermInfo> result = termInfoService.findAll(userId);
        return Result.ok(result);
    }

    @PostMapping("/saveBatch")
    public Result<Void> saveBatch(ServerWebExchange exchange, @RequestBody List<TermInfo> list) {
        Long userId = UserPermission.get(exchange).getUserId();
        termInfoService.saveBatch(userId, list);
        return Result.ok();
    }

}
